package com.leetcode;

/**
 * 883. 三维形体投影面积
 * 2022-04-26-每日一题
 *
 * @author fy
 * @date 2022/4/26 8:53
 */
public class Solution883 {

    public int projectionArea(int[][] grid) {
        int area1 = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] > 0) {
                    area1++;
                }
            }
        }

        int area2 = 0;
        for (int i = 0; i < grid.length; i++) {
            int temp = grid[i][0];
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] > temp) {
                    temp = grid[i][j];
                }
            }
            area2 += temp;
        }

        int area3 = 0;
        for (int j = 0; j < grid[0].length; j++) {
            int temp = grid[0][j];
            for (int i = 0; i < grid.length; i++) {
                if (grid[i][j] > temp) {
                    temp = grid[i][j];
                }
            }
            area3 += temp;
        }

        int sum = area1 + area2 + area3;
        return sum;
    }

}
